﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MainForm
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
            GUIHiding();
            this.connectionStrSettingsUC.Visible = true;
            this.localRepositoryPathUC.Visible = true;
            // set global parameters
            DAL.GenericDataAccess.SetConnectionString(Global.connectionString);
            TransformationHost.Global.LocalRepositoryPath = Global.LocalRepositoryPath;
            DTO.Webpage.LocalRepositoryPath = Global.LocalRepositoryPath;
        }


        /// <summary>
        /// Change the phase GUI in the main panel, when click to phases' tab
        /// </summary>
        private void ribbonMain_Click(object sender, EventArgs e)
        {
            GUIHiding();
            
            string curTabText = this.ribbonMain.ActiveTab.Text;
            switch (curTabText)
            {
                case "File":
                    connectionStrSettingsUC.Visible = true;
                    localRepositoryPathUC.Visible = true;
                    break;
                case "Preparation":
                    preparationHost.Visible = true;
                    break;
                case "Transformation":
                    transformationHost.Visible = true;
                    break;
                case "Regconition":
                    regconitionHost.Visible = true;
                    break;
                case "Clustering":
                    instanceClusteringHost.Visible = true;
                    break;
                case "Refinement":
                    refinementHost.Visible = true;
                    break;
                case "Revision":
                    revisionHost.Visible = true;
                    break;
            }
        }

        private void GUIHiding()
        {
            preparationHost.Visible = false;
            transformationHost.Visible = false;
            regconitionHost.Visible = false;
            connectionStrSettingsUC.Visible = false;
            localRepositoryPathUC.Visible = false;
            instanceClusteringHost.Visible = false;
            refinementHost.Visible = false;
            revisionHost.Visible = false;
        }

        private void ribbonButtonWebpageFilterSettings_Click(object sender, EventArgs e)
        {
            preparationHost.HideAllControl();
            preparationHost.groupBox_FilterSetting.Enabled = true;
        }

        private void ribbonButtonXHTMLConverterSettings_Click(object sender, EventArgs e)
        {
            preparationHost.HideAllControl();
            preparationHost.groupBox_Converter.Enabled = true;
        }

        private void ribbonButtonPreparationViewSettings_Click(object sender, EventArgs e)
        {
            preparationHost.HideAllControl();
            preparationHost.groupBox_PreparationView.Enabled = true;
        }

        private void ribbonButtonConnectionStringSet_Click(object sender, EventArgs e)
        {
            string conn = this.connectionStrSettingsUC.GetConnectionString();
            if (DAL.GenericDataAccess.TestConnectionString(conn) == true)
            {
                Global.connectionString = conn;
                DAL.GenericDataAccess.SetConnectionString(conn);
            }
            else
            {
                MessageBox.Show("This connection string is not working");
            }
        }

        private void ribbonButtonLocalRepositoryPathSet_Click(object sender, EventArgs e)
        {
            string path = this.localRepositoryPathUC.GetPath();
            if (string.IsNullOrEmpty(path) == false)
            {
                Global.LocalRepositoryPath = path;
                TransformationHost.Global.LocalRepositoryPath = Global.LocalRepositoryPath;
                DTO.Webpage.LocalRepositoryPath = Global.LocalRepositoryPath;
            }
        }
    }
}
